package com.ft.turorial.spring.boot.security.util;

import javax.servlet.http.HttpServletRequest;

import com.ft.turorial.spring.boot.security.vo.DeviceType;

public class DeviceUtil {
	public static DeviceType getDevice(HttpServletRequest request) {
		 String requestHeader = request.getHeader("user-agent");
		     /* android : 所有android
             * mac os  :  iphone ipad
	         * windows  :  phone:Nokia等windows系统的手机
	         */
	        //String[] deviceArray = new String[]{"android","mac os","windows phone"};
	     if(requestHeader == null){
	    	 return null;	    	 
	     }
	     requestHeader = requestHeader.toLowerCase();
	     if ( requestHeader.indexOf("android") >=0 ) {
	    	 return DeviceType.ANDROID;
	     } else if (requestHeader.indexOf("phone") >=0) {
	    	 return DeviceType.WINPhone;
	     } else if (requestHeader.indexOf("mac") >=0) {
	    	 return DeviceType.MAC;
	     } else {
	    	 return DeviceType.PC;
	     }
	}
	
	public static boolean isMobile(HttpServletRequest request) {
		DeviceType type= getDevice(request);
		
		if (type == DeviceType.PC) {
			return false;
		}
		return true;
	}
	
}
